

package gamepack;

import java.util.*;


public class NotificationManager {
	//static Vector<NotificationHandler> vecHandlers = new Vector<NotificationHandler>();
	static Map<String,Vector<NotificationHandler> >  mapOfHandlers = new HashMap<String,Vector<NotificationHandler> >();
	
	public static void register(String type,NotificationHandler nh) {
		Vector<NotificationHandler> vecHandlers = mapOfHandlers.get(type);
		if( vecHandlers == null ) {
			vecHandlers = new Vector<NotificationHandler>();
			mapOfHandlers.put( type, vecHandlers );
		}
		vecHandlers.add( nh );
	}
	
	public static void unregister(String type,NotificationHandler nh) {
		Vector<NotificationHandler> vecHandlers = mapOfHandlers.get(type);
		if( vecHandlers != null ) {
			vecHandlers.remove(nh);
			return;
		}		
	}
	
	public static void sendNotification(String type) {
		Notification n = new Notification(type);		
		sendNotification(n);
	}
	
	public static void sendNotification(Notification n) {
		String type = n.type;
		Vector<NotificationHandler> vecHandlers = mapOfHandlers.get(type);
		if( vecHandlers != null ) {
			for(int i=0;i<vecHandlers.size();i++) {
				vecHandlers.get(i).handleNotification(n);
			}
		}
	}
	
}